package com.demo.applicationlistener.eventlistener;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.demo.applicationlistener.eventlistener.domain.Halo;
import com.demo.applicationlistener.eventlistener.myevent.HaloEvent;
import com.demo.utils.applicationcontext.SpringContextUtil;

@RestController
@RequestMapping("/event")
public class EventController {

	@RequestMapping("/test")
	public String halo(String who, String say, HttpServletRequest request) {
		ApplicationContext applicationContext = SpringContextUtil.getApplicationContext();
		Halo halo = new Halo(who, say);
		HaloEvent bookingCreatedEvent = new HaloEvent(this, request, halo);
		// 触发event
		applicationContext.publishEvent(bookingCreatedEvent);

		return who + "--" + say;

	}
}
